<template>
  <div class="app-container">
    <!-- 高级查询 -->
    <el-form v-show="searchVisible" ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item label="原主键:">
        <el-input v-model="queryParams.seqId" size="small" placeholder="请输入原主键" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="LOT 编号:">
        <el-input v-model="queryParams.lotCd" size="small" placeholder="请输入LOT 编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="仓库编号:">
        <el-input v-model="queryParams.whCd" size="small" placeholder="请输入仓库编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="箱子编号:">
        <el-input v-model="queryParams.contianboxCd" size="small" placeholder="请输入箱子编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="lot 当前体积已用率:">
        <el-input v-model="queryParams.totVolOcpPct" size="small" placeholder="请输入lot 当前体积已用率" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="LOT当前重量已用率:">
        <el-input v-model="queryParams.totWtOcpPct" size="small" placeholder="请输入LOT当前重量已用率" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="CELL 编码:">
        <el-input v-model="queryParams.cellCd" size="small" placeholder="请输入CELL 编码" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="版本号:">
        <el-input v-model="queryParams.version" size="small" placeholder="请输入版本号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="是否最后入的箱子:">
        <el-input v-model="queryParams.containLastInYn" size="small" placeholder="请输入是否最后入的箱子" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="创建时间:">
        <el-date-picker v-model="queryParams.createDate" type="date" value-format="yyyy-MM-dd" size="small" placeholder="选择创建时间" clearable />
      </el-form-item>
      <el-form-item label="更新时间:">
        <el-date-picker v-model="queryParams.updateDate" type="date" value-format="yyyy-MM-dd" size="small" placeholder="选择更新时间" clearable />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button v-hasPermission="['module:tWhContainboxInLotTb:insert']" type="primary" icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermission="['module:tWhContainboxInLotTb:update']" type="success" icon="el-icon-edit" size="mini" :disabled="isSingle" @click="handleEdit">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermission="['module:tWhContainboxInLotTb:delete']" type="danger" icon="el-icon-delete" size="mini" :disabled="isMultiple" @click="handleRemove">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermission="['module:tWhContainboxInLotTb:export']" type="warning" icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
      </el-col>
      <right-toolbar :show-search.sync="searchVisible" @queryTable="handleQuery" />
    </el-row>

    <!-- 数据列表 -->
    <el-table v-loading="loading" :data="page.records" highlight-current-row @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="原主键" align="center" prop="seqId" />
      <el-table-column label="LOT 编号" align="center" prop="lotCd" />
      <el-table-column label="仓库编号" align="center" prop="whCd" />
      <el-table-column label="箱子编号" align="center" prop="contianboxCd" />
      <el-table-column label="lot 当前体积已用率" align="center" prop="totVolOcpPct" />
      <el-table-column label="LOT当前重量已用率" align="center" prop="totWtOcpPct" />
      <el-table-column label="CELL 编码" align="center" prop="cellCd" />
      <el-table-column label="版本号" align="center" prop="version" />
      <el-table-column label="是否最后入的箱子" align="center" prop="containLastInYn" />
      <el-table-column label="记录 ID，系统自动产生" align="center" prop="id" />
      <el-table-column label="创建时间" align="center" prop="createDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新时间" align="center" prop="updateDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button v-hasPermission="['module:tWhContainboxInLotTb:update']" size="mini" type="text" icon="el-icon-edit" @click="handleEdit(scope.row)">修改</el-button>
          <el-button v-hasPermission="['module:tWhContainboxInLotTb:delete']" size="mini" type="text" icon="el-icon-delete" @click="handleRemove(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <pagination v-show="page.total>0" :total="page.total" :page.sync="page.current" :limit.sync="page.pageSize" @pagination="handleQuery" />

    <!-- 添加/修改对话框 -->
    <el-dialog :title="tWhContainboxInLotTbFormDialog.title" :visible.sync="tWhContainboxInLotTbFormDialog.visible" :close-on-click-modal="false" :before-close="resetTWhContainboxInLotTbFormDialog" width="500px" append-to-body>
      <el-form ref="tWhContainboxInLotTbForm" :model="tWhContainboxInLotTbFormData" :rules="tWhContainboxInLotTbFormRules" label-width="80px">
        <el-form-item label="原主键" prop="seqId">
          <el-input v-model="tWhContainboxInLotTbFormData.seqId" placeholder="请输入原主键" />
        </el-form-item>
        <el-form-item label="LOT 编号" prop="lotCd">
          <el-input v-model="tWhContainboxInLotTbFormData.lotCd" placeholder="请输入LOT 编号" />
        </el-form-item>
        <el-form-item label="仓库编号" prop="whCd">
          <el-input v-model="tWhContainboxInLotTbFormData.whCd" placeholder="请输入仓库编号" />
        </el-form-item>
        <el-form-item label="箱子编号" prop="contianboxCd">
          <el-input v-model="tWhContainboxInLotTbFormData.contianboxCd" placeholder="请输入箱子编号" />
        </el-form-item>
        <el-form-item label="lot 当前体积已用率" prop="totVolOcpPct">
          <el-input v-model="tWhContainboxInLotTbFormData.totVolOcpPct" placeholder="请输入lot 当前体积已用率" />
        </el-form-item>
        <el-form-item label="LOT当前重量已用率" prop="totWtOcpPct">
          <el-input v-model="tWhContainboxInLotTbFormData.totWtOcpPct" placeholder="请输入LOT当前重量已用率" />
        </el-form-item>
        <el-form-item label="CELL 编码" prop="cellCd">
          <el-input v-model="tWhContainboxInLotTbFormData.cellCd" placeholder="请输入CELL 编码" />
        </el-form-item>
        <el-form-item label="版本号" prop="version">
          <el-input v-model="tWhContainboxInLotTbFormData.version" placeholder="请输入版本号" />
        </el-form-item>
        <el-form-item label="是否最后入的箱子" prop="containLastInYn">
          <el-input v-model="tWhContainboxInLotTbFormData.containLastInYn" placeholder="请输入是否最后入的箱子" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createDate">
          <el-date-picker v-model="tWhContainboxInLotTbFormData.createDate" type="date" value-format="yyyy-MM-dd" size="small" style="width: 100%" placeholder="选择创建时间" clearable />
        </el-form-item>
        <el-form-item label="更新时间" prop="updateDate">
          <el-date-picker v-model="tWhContainboxInLotTbFormData.updateDate" type="date" value-format="yyyy-MM-dd" size="small" style="width: 100%" placeholder="选择更新时间" clearable />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirmTWhContainboxInLotTbFormDialog">确 定</el-button>
        <el-button @click="resetTWhContainboxInLotTbFormDialog">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import TWhContainboxInLotTbApi from '@/api/module/TWhContainboxInLotTbApi'

const defaultTWhContainboxInLotTbFormData = {
  seqId: null,
  lotCd: null,
  whCd: null,
  contianboxCd: null,
  totVolOcpPct: null,
  totWtOcpPct: null,
  cellCd: null,
  version: null,
  containLastInYn: null,
  createDate: null,
  updateDate: null,
}
export default {
  name: 'TWhContainboxInLotTbList',
  data() {
    return {
      options: {
        sysYnTypeOptions: this.$constant.sysYnTypeOptions
      },
      queryParams: {
        seqId: null,
        lotCd: null,
        whCd: null,
        contianboxCd: null,
        totVolOcpPct: null,
        totWtOcpPct: null,
        cellCd: null,
        version: null,
        containLastInYn: null,
        createDate: null,
        updateDate: null,
        isValid: this.$constant.Y
      },
      page: {
        current: 1,
        pageSize: 10,
        total: 0,
        records: []
      },
      tWhContainboxInLotTbFormDialog: {
        title: '',
        visible: false
      },
      tWhContainboxInLotTbFormData: Object.assign({}, defaultTWhContainboxInLotTbFormData),
      tWhContainboxInLotTbFormRules: {
        seqId: [{ required: true, message: '原主键不能为空', trigger: 'blur' }],

        createDate: [{ required: true, message: '创建时间不能为空', trigger: 'blur' }],

        updateDate: [{ required: true, message: '更新时间不能为空', trigger: 'blur' }],

      },
      loading: true,
      searchVisible: true,
      multipleSelection: [],
      isSingle: true,
      isMultiple: true
    }
  },
  created() {
    this.handleQuery()
    this.loadOptions()
  },
  methods: {
    loadOptions() {
    },
    handleAdd() {
      this.openTWhContainboxInLotTbFormDialog()
    },
    handleRemove(row) {
      const ids = row.id || this.multipleSelection.map(item => item.id)
      this.$confirm('是否确认删除数据?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return TWhContainboxInLotTbApi.remove(ids)
      }).then(() => {
        this.handleQuery()
        this.$message.success('删除成功')
      })
    },
    handleEdit(row) {
      const id = row.id || this.multipleSelection.map(item => item.id)[0]
      this.openTWhContainboxInLotTbFormDialog(id)
    },
    handleQuery() {
      this.loading = true
      TWhContainboxInLotTbApi.page(this.queryParams, this.page).then(response => {
        this.page.records = response.data.records
        this.page.total = response.data.total
        this.loading = false
      }, () => {
        this.loading = false
      })
    },
    handleExport() {
      this.$confirm('是否确认导出数据?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return TWhContainboxInLotTbApi.exportData(this.queryParams)
      }).then(response => {
        this.$common.download(response.msg)
      })
    },
    openTWhContainboxInLotTbFormDialog(id) {
      this.tWhContainboxInLotTbFormDialog.visible = true
      if (id) {
        this.tWhContainboxInLotTbFormDialog.title = '库区仓储容器-修改'
        TWhContainboxInLotTbApi.get(id).then(response => {
          this.tWhContainboxInLotTbFormData = {
            ...this.tWhContainboxInLotTbFormData,
            ...response.data
          }
        })
      } else {
        this.tWhContainboxInLotTbFormDialog.title = '库区仓储容器-添加'
      }
    },
    confirmTWhContainboxInLotTbFormDialog() {
      this.$refs['tWhContainboxInLotTbForm'].validate(valid => {
        if (valid) {
          if (this.tWhContainboxInLotTbFormData.id) {
            TWhContainboxInLotTbApi.edit(this.tWhContainboxInLotTbFormData).then(response => {
              this.$message.success('修改成功')
              this.resetTWhContainboxInLotTbFormDialog()
              this.handleQuery()
            })
          } else {
            TWhContainboxInLotTbApi.add(this.tWhContainboxInLotTbFormData).then(response => {
              this.$message.success('添加成功')
              this.resetTWhContainboxInLotTbFormDialog()
              this.handleQuery()
            })
          }
        }
      })
    },
    resetTWhContainboxInLotTbFormDialog() {
      this.tWhContainboxInLotTbFormDialog = {
        title: '',
        visible: false
      }
      this.tWhContainboxInLotTbFormData = Object.assign({}, defaultTWhContainboxInLotTbFormData)
      this.resetForm('tWhContainboxInLotTbForm')
    },
    handleSelectionChange(selection) {
      this.multipleSelection = selection
      this.isSingle = selection.length !== 1
      this.isMultiple = !selection.length
    },
    resetQuery() {
      this.page.current = 1
      this.resetForm('queryForm')
      this.handleQuery()
    }
  }
}
</script>
